/*
 * user-db.js
 */

const {
  selectQuery
} = require('./db-helper')

const $sql = {
  insert_log_notice:
      'INSERT INTO log_notice (mac,time,imgUrl,nickname) VALUES (?,?,?,?)',
  insert_gce_token:
      'INSERT INTO gce_token (mac,token,uniqueId,time) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE time=?,uniqueId=?',
  insert_camera_ip:
      'INSERT INTO camera_ip (mac,ip,datetime,rtmpUrl) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE ip=?,datetime=?',
  select_gce_token:
      'SELECT token FROM gce_token WHERE mac = ?',
  select_camera_ip:
      'select a.mac,IFNULL(b.ip, "") as ip,b.rtmpUrl FROM gce_token a LEFT JOIN camera_ip b on a.mac=b.mac WHERE token =?',
}

exports.insertLogNotice = (...params) => selectQuery($sql.insert_log_notice, ...params)
exports.insertGceToken = (...params) => selectQuery($sql.insert_gce_token, ...params)
exports.insertCameraIp = (...params) => selectQuery($sql.insert_camera_ip, ...params)
exports.selectGceToken = (...params) => selectQuery($sql.select_gce_token, ...params)
exports.selectCameraIp = (...params) => selectQuery($sql.select_camera_ip, ...params)